#coding=utf-8
#Boa:FramePanel:PanelDeliveryPlanList

import wx

from wx.lib.splitter import MultiSplitterWindow

from ctrlAider import MyComboBoxDecorator
from MyListCtrl import MyListCtrlDeliveryPlan,MyListCtrlDeliverySaleOrder,MyOrderContentListCtrl
from product import CDataDeliveryState


[wxID_PANELDELIVERYPLANLIST, wxID_PANELDELIVERYPLANLISTBTNDONE, 
 wxID_PANELDELIVERYPLANLISTBTNPLANING, wxID_PANELDELIVERYPLANLISTBTNSENDING, 
 wxID_PANELDELIVERYPLANLISTBTNSHOWALL, wxID_PANELDELIVERYPLANLISTCOMBOSTATE, 
 wxID_PANELDELIVERYPLANLISTTSTATE, 
] = [wx.NewId() for _init_ctrls in range(7)]

class PanelDeliveryPlanList(wx.Panel):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Panel.__init__(self, id=wxID_PANELDELIVERYPLANLIST,
              name=u'PanelDeliveryPlanList', parent=prnt, pos=wx.Point(114, 39),
              size=wx.Size(1053, 698), style=wx.TAB_TRAVERSAL)
        self.SetClientSize(wx.Size(1045, 664))
        self.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False,
              u'\u6977\u4f53_GB2312'))
        self.SetBackgroundColour(wx.Colour(183, 209, 173))

        self.comboState = wx.ComboBox(choices=[],
              id=wxID_PANELDELIVERYPLANLISTCOMBOSTATE, name=u'comboState',
              parent=self, pos=wx.Point(80, 8), size=wx.Size(150, 24), style=0,
              value=u'')
        self.comboState.SetLabel(u'')
        self.comboState.Bind(wx.EVT_COMBOBOX, self.OnComboStateCombobox,
              id=wxID_PANELDELIVERYPLANLISTCOMBOSTATE)

        self.tState = wx.StaticText(id=wxID_PANELDELIVERYPLANLISTTSTATE,
              label=u'\u72b6\u6001\uff1a', name=u'tState', parent=self,
              pos=wx.Point(16, 16), size=wx.Size(51, 16), style=0)

        self.btnShowAll = wx.Button(id=wxID_PANELDELIVERYPLANLISTBTNSHOWALL,
              label=u'\u663e\u793a\u5168\u90e8', name=u'btnShowAll',
              parent=self, pos=wx.Point(240, 8), size=wx.Size(93, 26), style=0)
        self.btnShowAll.Bind(wx.EVT_BUTTON, self.OnBtnShowAllButton,
              id=wxID_PANELDELIVERYPLANLISTBTNSHOWALL)

        self.btnPlaning = wx.Button(id=wxID_PANELDELIVERYPLANLISTBTNPLANING,
              label=u'\u8ba1\u5212\u4e2d', name=u'btnPlaning', parent=self,
              pos=wx.Point(352, 8), size=wx.Size(72, 26), style=0)
        self.btnPlaning.Bind(wx.EVT_BUTTON, self.OnBtnPlaningButton,
              id=wxID_PANELDELIVERYPLANLISTBTNPLANING)

        self.btnSending = wx.Button(id=wxID_PANELDELIVERYPLANLISTBTNSENDING,
              label=u'\u51fa\u8f66\u4e2d', name=u'btnSending', parent=self,
              pos=wx.Point(432, 8), size=wx.Size(72, 26), style=0)
        self.btnSending.Bind(wx.EVT_BUTTON, self.OnBtnSendingButton,
              id=wxID_PANELDELIVERYPLANLISTBTNSENDING)

        self.btnDone = wx.Button(id=wxID_PANELDELIVERYPLANLISTBTNDONE,
              label=u'\u5df2\u5b8c\u6210', name=u'btnDone', parent=self,
              pos=wx.Point(512, 8), size=wx.Size(72, 26), style=0)
        self.btnDone.Bind(wx.EVT_BUTTON, self.OnBtnDoneButton,
              id=wxID_PANELDELIVERYPLANLISTBTNDONE)

    def __init__(self, parent):
        self._init_ctrls(parent)
        
        self.cbState = MyComboBoxDecorator(self.comboState, CDataDeliveryState, CDataDeliveryState.fi_name)
        self.cbState.refresh()
        
        self.splitterWin = MultiSplitterWindow(self, style=wx.SP_LIVE_UPDATE)
        
        self.lcPlan = MyListCtrlDeliveryPlan(self.splitterWin)
        #self.lcPlan.Move(wx.Point(10, 40))
        #self.lcPlan.SetSize(wx.Size(950, 150))
        self.lcPlan.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected)
        
        self.lcBill = MyListCtrlDeliverySaleOrder(self.splitterWin)
        #self.lcBill.Move(wx.Point(10, 200))
        #self.lcBill.SetSize(wx.Size(950, 200))
        self.lcBill.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnBillItemSelected)
        
        self.lcContent = MyOrderContentListCtrl(self.splitterWin)
        #self.lcContent.Move(wx.Point(10, 410))
        #self.lcContent.SetSize(wx.Size(950, 200))
        
        self.lcPlan.SetMinSize(wx.Size(950, 50))
        self.splitterWin.AppendWindow(self.lcPlan, 150)
        
        self.lcBill.SetMinSize(wx.Size(950, 50))
        self.splitterWin.AppendWindow(self.lcBill, 200)
        
        self.lcContent.SetMinSize(wx.Size(950, 50))
        self.splitterWin.AppendWindow(self.lcContent)
        
        self.splitterWin.Move(wx.Point(16, 40))
        # ？？设置大小为什么必须放在最后？放在AppendWindow之前导致sashPos参数不起作用
        self.splitterWin.SetSize(wx.Size(1000, 550))
        self.splitterWin.SetOrientation(wx.VERTICAL)
        self.splitterWin.SizeWindows()
    
    def OnBillItemSelected(self, event):
        '''按照选中订单，显示订单内容'''
        item = self.lcBill.GetNextItem(-1, state = wx.LIST_STATE_SELECTED)
        billId = self.lcBill.getBillId(item)
        self.lcContent.refresh({'billId':billId})
        
    def OnItemSelected(self, event):
        planId = self.lcPlan.getPlanId()
        self.lcBill.refresh({'deliveryPlan':planId})
        
    def OnBtnNewQuickButton(self, event):
        event.Skip()

    def refreshPlanList(self):
        obj = self.cbState.getSelectObj()
        self.lcPlan.refresh({'state':obj.getKeyVal()})
        
    def OnComboStateCombobox(self, event):
        self.refreshPlanList()

    def OnBtnShowAllButton(self, event):
        self.cbState.SetValue(u'')
        self.lcPlan.refresh()

    def OnBtnPlaningButton(self, event):
        self.cbState.SetValue(self.btnPlaning.GetLabel())
        self.refreshPlanList()
        #event.Skip()

    def OnBtnSendingButton(self, event):
        self.cbState.SetValue(self.btnSending.GetLabel())
        self.refreshPlanList()
        #event.Skip()

    def OnBtnDoneButton(self, event):
        self.cbState.SetValue(self.btnDone.GetLabel())
        self.refreshPlanList()
        #event.Skip()
